package com.noble.glamour.ui.discover;

import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.noble.glamour.R;
import com.noble.glamour.bean.config.base.Pay;
import com.noble.glamour.module.logic.application.ModuleMgr;
import com.noble.library.view.base.BaseDialogFragment;
import com.noble.glamour.module.util.UIShow;
import com.noble.glamour.ui.user.paygoods.GoodsConstant;
import com.noble.glamour.ui.user.paygoods.GoodsPayTypePanel;
import com.noble.library.utils.ViewUtils;

/**
 * Created by duanzheng on 2017/7/17.
 * 开通vip
 */

public class OpeningVipDialog extends BaseDialogFragment implements View.OnClickListener {
    private int vip_day = 0;
    private RelativeLayout day_90;
    private RelativeLayout day_30;
    private ImageView day_30_select_iv;
    private ImageView day_90_select_iv;
    private LinearLayout pay_type_layout;
    private TextView send, tv_month_welfare, tv_quarter_welfare;
    private GoodsPayTypePanel payTypePanel;
    private LinearLayout root;
    private LinearLayout content;


    public OpeningVipDialog() {
        settWindowAnimations(R.style.AnimDownInDownOutOverShoot);
        setGravity(Gravity.BOTTOM);
        setDialogSizeRatio(-2, -2);
        setCancelable(true);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        super.onCreateView(inflater, container, savedInstanceState);
        setContentView(R.layout.f1_openvip_bottom_dlg);
        View contentView = getContentView();
        initView(contentView);
        initData();
        return contentView;
    }

    private void initView(View contentView) {
        day_90 = (RelativeLayout) contentView.findViewById(R.id.day_90);
        day_30 = (RelativeLayout) contentView.findViewById(R.id.day_30);

        send = (TextView) contentView.findViewById(R.id.send);

        day_30_select_iv = (ImageView) contentView.findViewById(R.id.day_30_select_iv);
        day_90_select_iv = (ImageView) contentView.findViewById(R.id.day_90_select_iv);

        pay_type_layout = (LinearLayout) contentView.findViewById(R.id.pay_type);
        root = (LinearLayout) contentView.findViewById(R.id.root);
        content = (LinearLayout) contentView.findViewById(R.id.content);

        tv_month_welfare = ViewUtils.findById(contentView, R.id.tv_month_welfare);
        tv_quarter_welfare = ViewUtils.findById(contentView, R.id.tv_quarter_welfare);

    }

    private void initData() {
        day_90.setSelected(true);
        vip_day = 89;
        day_30_select_iv.setVisibility(View.GONE);
        day_90_select_iv.setVisibility(View.VISIBLE);

        day_30.setSelected(false);
        day_90.setOnClickListener(this);
        day_30.setOnClickListener(this);
        root.setOnClickListener(this);
        content.setOnClickListener(this);
        payTypePanel = new GoodsPayTypePanel(getContext(), GoodsConstant.PAY_TYPE_NEW);
        pay_type_layout.addView(payTypePanel.getContentView());

        send.setOnClickListener(this);
        Pay pay = ModuleMgr.getCommonMgr().getCommonConfig().getPay();
        if (pay.getQuarterWelfare() != null && pay.getQuarterWelfare().trim().length() > 0) {
            tv_quarter_welfare.setText(pay.getQuarterWelfare());
        } else {
            tv_quarter_welfare.setText("");
        }
        if (pay.getMonthWelfare() != null && pay.getMonthWelfare().trim().length() > 0) {
            tv_month_welfare.setText(pay.getMonthWelfare());
        } else {
            tv_month_welfare.setText("");
        }
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.day_90:
                vip_day = 89;
                day_90.setSelected(true);
                day_30.setSelected(false);

                day_30_select_iv.setVisibility(View.GONE);
                day_90_select_iv.setVisibility(View.VISIBLE);

                break;
            case R.id.day_30:
                vip_day = 69;
                day_90.setSelected(false);
                day_30.setSelected(true);

                day_30_select_iv.setVisibility(View.VISIBLE);
                day_90_select_iv.setVisibility(View.GONE);
                break;
            case R.id.send:
                dismiss();
                UIShow.showPayAlipayt(getActivity(), vip_day, payTypePanel.getPayType(), 0, "");
                break;
            case R.id.content:
                break;
            case R.id.root:
                dismiss();
                break;

        }
    }
}
